<?php
defined('BASEPATH') or exit('No direct script access allowed');
require_once 'DB/MysqlModel.php';

class ChatComment extends MysqlModel
{

    public $table = 'chat_comment';

    public function __construct()
    {
        parent::__construct();
        parent::setTable($this->table);
    }
    
    public function getComment($userId){
        $table = $this->table;
        $this->db->select("u.username,c.*");
        $this->db->from("$table as c");
        $this->db->join('robot_user as u',"u.id=c.commenter_id");
        $this->db->where('c.user_id',$userId);
        $this->db->where('c.is_valid',1);
        $this->db->order_by('update_time desc');
        $query = $this->db->get();
        $result = $query->result_array();
        foreach ($result as $k=>$res){
            $result[$k]['update_time'] = date('Y-m-d H:i:s', $res['update_time']);
        }
        return $result;
    }
    
    public function logicDelete($id){
        $table = $this->table;
        $this->db->where('id', $id);
        $res = $this->db->update($table, array('is_valid'=> 0));
        return $res;
    }
    
}

